//==========================================================================
// Copyright (c) 2000-2006,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

#include <string.h>

char * __cdecl _strlwr(char * string)
{
/*
    register char * __res;
#if !defined(_arm)
    int d0;
    asm __volatile__(
        "movl %3, %0\n"
        "1:\tmovl (%%esi), %%ebx\n\t"
        "cmp $0, %%ebx\n\t"
        "je 3f\n\t"
        "cmp $0x41, %%bl\n\t"
        "jb 2f\n\t"
        "cmp $0x5a, %%bl\n\t"
        "ja 2f\n\t"
        "add $0x20, %%bl\n\t"
        "movb %%bl, (%%esi)\n\t"
        "2:\tincl %%esi\n\t"
        "jmp 1b\n"
        "3:\n"
        :"=a"(__res), "=&S" (d0)
        :"0" (0), "1" (string)
        :"bx");
#else
    asm __volatile__(
        "1:\tldrb r1, [r0]\n\t"
        "cmp r1, $0\n\t"
        "beq 3f\n\t"
        "cmp r1, #0x41\n\t"
        "blt 2f\n\t"
        "cmp r1, #0x5a\n\t"
        "bhi 2f\n\t"
        "add r1, r1, #0x20\n"
        "strb r2, [r1]\n"
        "2:\tadd r1, r1, #1\n\t"
        "b 1b\n"
        "3:\n"
        :"=r"(__res)
        ::"r1");
#endif

    return __res;
*/
    char * cp;

    for (cp = string; *cp;++cp) {
        if ('A' <= *cp && *cp <= 'Z')
            *cp += 'a' - 'A';
    }

    return(string);
}

wchar_t * __cdecl _wcslwr(wchar_t * string)
{
/*
    register wchar_t * __res;
#if !defined(_arm)
    int d0;
    asm __volatile__(
        "movl %3, %0\n"
        "1:\tmovl (%%esi), %%ebx\n\t"
        "cmp $0, %%ebx\n\t"
        "je 3f\n\t"
        "cmp $0x41, %%bx\n\t"
        "jb 2f\n\t"
        "cmp $0x5a, %%bx\n\t"
        "ja 2f\n\t"
        "add $0x20, %%bx\n\t"
        "movw %%bx, (%%esi)\n\t"
        "2:\taddl $2, %%esi\n\t"
        "jmp 1b\n"
        "3:\n"
        :"=a"(__res), "=&S" (d0)
        :"0" (0), "1" (string)
        :"bx");
#else
    asm __volatile__(
        "1:\tldrh r1, [r0]\n\t"
        "cmp r1, $0\n\t"
        "beq 3f\n\t"
        "cmp r1, #0x41\n\t"
        "blt 2f\n\t"
        "cmp r1, #0x5a\n\t"
        "bhi 2f\n\t"
        "add r1, r1, #0x20\n"
        "str r2, [r1]\n"
        "2:\tadd r1, r1, #2\n\t"
        "b 1b\n"
        "3:\n"
        :"=r"(__res)
        ::"r1");
#endif

    return __res;
*/
    wchar_t * cp;

    for (cp = string; *cp;++cp) {
        if (L'A' <= *cp && *cp <= L'Z')
            *cp += L'a' - L'A';
    }

    return(string);
}

char * __cdecl _strupr(char * string)
{
/*
    register char * __res;
#if !defined(_arm)
    int d0;
    asm __volatile__(
        "movl %3, %0\n"
        "1:\tmovl (%%esi), %%ebx\n\t"
        "cmp $0, %%ebx\n\t"
        "je 3f\n\t"
        "cmp $0x61, %%bl\n\t"
        "jb 2f\n\t"
        "cmp $0x7a, %%bl\n\t"
        "ja 2f\n\t"
        "sub $0x20, %%bl\n\t"
        "movb %%bl, (%%esi)\n\t"
        "2:\tincl %%esi\n\t"
        "jmp 1b\n"
        "3:\n"
        :"=a"(__res), "=&S" (d0)
        :"0" (0), "1" (string)
        :"bx");
#else
    asm __volatile__(
        "1:\tldrh r1, [r0]\n\t"
        "cmp r1, $0\n\t"
        "beq 3f\n\t"
        "cmp r1, #0x41\n\t"
        "blt 2f\n\t"
        "cmp r1, #0x5a\n\t"
        "bhi 2f\n\t"
        "sub r1, r1, #0x20\n"
        "str r2, [r1]\n"
        "2:\tadd r1, r1, #1\n\t"
        "b 1b\n"
        "3:\n"
        :"=r"(__res)
        ::"r1");
#endif

    return __res;
*/
    char * cp;

    for (cp = string; *cp;++cp) {
        if ('a' <= *cp && *cp <= 'z')
            *cp += 'A' - 'a';
    }

    return(string);
}

wchar_t * __cdecl _wcsupr(wchar_t * string)
{
/*
    register wchar_t * __res;
#if !defined(_arm)
    int d0;
    asm __volatile__(
        "movl %3, %0\n"
        "1:\tmovl (%%esi), %%ebx\n\t"
        "cmp $0, %%ebx\n\t"
        "je 3f\n\t"
        "cmp $0x61, %%bx\n\t" //convert to upper case.
        "jb 2f\n\t"
        "cmp $0x7a, %%bx\n\t"
        "ja 2f\n\t"
        "sub $0x20, %%bx\n\t"
        "movw %%bx, (%%esi)\n\t"
        "2:\taddl $2, %%esi\n\t"
        "jmp 1b\n"
        "3:\n"
        :"=a"(__res), "=&S" (d0)
        :"0" (0), "1" (string)
        :"bx");
#else
    asm __volatile__(
        "1:\tldr r1, [r0]\n\t"
        "cmp r1, $0\n\t"
        "beq 3f\n\t"
        "cmp r1, #0x41\n\t"
        "blt 2f\n\t"
        "cmp r1, #0x5a\n\t"
        "bhi 2f\n\t"
        "sub r1, r1, #0x20\n"
        "str r2, [r1]\n"
        "2:\tadd r1, r1, #2\n\t"
        "b 1b\n"
        "3:\n"
        :"=r"(__res)
        ::"r1");
#endif

    return __res;
*/
    wchar_t * cp;

    for (cp = string; *cp;++cp) {
        if (L'a' <= *cp && *cp <= L'z')
            *cp += L'A' - L'a';
    }

    return(string);
}
